// pages/goDutchBefore/goDutchBefore.js
import {
  request,
  requestHasToken
} from '../../service/network'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    groups: [],
    pageAdd: false,//多次下拉后 没有数据就不要加载了
    gm: false,
    admin: 0,
    examineNums:0
  },
 /*  handleBack() {
    wx.navigateBack({
      delta: 1
    })
  }, */
  onLoad() {
    setTimeout(() => {
      this.setData({
        admin: wx.getStorageSync('userInfo').admin
      })
    }, 1000);
    let counter = setInterval(() => {
      if (wx.getStorageSync('token') != '') {
        this.addGoDutch()
        clearInterval(counter)
        this.setData({
          gm: false
        })
      }else {
        this.setData({
          gm: true
        })
      }
    }, 500);
    requestHasToken({
      url: 'api/go/dutch/unExamineNums',
      data: {
        examine:'未审核'
      }
    }).then((res) => {
      if (res.data.code == 0) {
        //多次下拉后 没有数据就不要加载了
        this.setData({
          examineNums:res.data.data,
        })
      }
    })
  },
  addGoDutch() {
    if(!this.loginPage()) {return false}
    // this.setData({
    //   gm: false
    // })
    requestHasToken({
      url: 'api/go/dutch/listExamine',
      data: {
        page: this.data.page,
        limit: 10,
      }
    }).then((res) => {
      if (res.data.code == 0) {
        //多次下拉后 没有数据就不要加载了
        if(res.data.data.length==0) {
          this.setData({
            pageAdd: true
          })
        }
        let groups2 = this.data.groups
        groups2.push(...res.data.data)
        this.setData({
          groups: groups2,
        })
      }
    })
  },
  handleAdd(res) {
    // if (this.loginPage()) {
      wx.navigateTo({
        url: '/pages/goDutchCURD/goDutchCURD'
      })
    // }
  },
  handleExamine(res) {
      wx.navigateTo({
        url: '/pages/goDutchCURD/goDutchCURD'
      })
  },
  loginPage() {
    if (wx.getStorageSync('token') ) {
      return true
    } else {
      return false
    }
  },
  loginAction(){
    wx.redirectTo({
      url: '/pages/login/login?url=/pages/goDutchBefore/goDutchBefore'
    })
  },
  onReachBottom() {
    this.setData({
      page: this.data.page + 1
    })
    this.addGoDutch()
  },
})